package eleven;

/**
 *2609. 最长平衡子字符串
 */
public class Day08 {

    public int findTheLongestBalancedSubstring(String s) {
        int i = 0,j = 0,k = 0,maxL = 0;
        int n = s.length();
        while(i < n && s.charAt(i) == '1') i++;
        j = i;
        while (i < n && j < n && k < n){
            while (j < n && s.charAt(j) == '0') j++;
            k = j;
            while (k < n && s.charAt(k) == '1') k++;
            maxL = Math.max(maxL,Math.min(j-i,k-j)*2);
            i = k;
            j = k;
        }
        return maxL;
    }
    public static void main(String[] args) {
        Day08 day08 = new Day08();
        System.out.println(day08.findTheLongestBalancedSubstring("0101"));
    }
}
